//
//  XLAboutUsAdapter.m
//  industry
//
//  Created by xl on 2020/12/31.
//  Copyright © 2020 Haier. All rights reserved.
//

#import "XLAboutUsAdapter.h"
#import "XLTitleInfoArrowLineCell.h"

NSString *const XLAboutUsAdapterVersion = @"XLAboutUsAdapterVersion";
NSString *const XLAboutUsAdapterCompanyInfo = @"XLAboutUsAdapterCompanyInfo";

@implementation XLAboutUsAdapter

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.getAdapterArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 64.0f;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row > self.getAdapterArray.count - 1) {
        return [UITableViewCell new];
    }
    id data = self.getAdapterArray[indexPath.row];
    static NSString *cellIdentifierId = @"XLTitleInfoArrowLineCell";
    XLTitleInfoArrowLineCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifierId];
    if (!cell) {
        cell = [[XLTitleInfoArrowLineCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifierId];
    }
    if ([data isEqualToString:XLAboutUsAdapterVersion]) {
        [cell loadCellData:@"版本说明" info:[NSString stringWithFormat:@"当前版本V%@", XLAPPVERSION] isShowArrow:NO];
    } else if ([data isEqualToString:XLAboutUsAdapterCompanyInfo]) {
        [cell loadCellData:@"公司简介" info:@"" isShowArrow:YES];
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row > self.getAdapterArray.count - 1) {
        return;
    }
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    id cellData = self.getAdapterArray[indexPath.row];
    
    if (self.adapterDelegate && [self.adapterDelegate respondsToSelector:@selector(didSelectCellData:)]) {
        [self.adapterDelegate didSelectCellData:cellData];
    }
}
@end
